package logic

import (
	"context"
	"fmt"
	"e4ting/internal/svc"
	"e4ting/pb/e4ting"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUTXOLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUTXOLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUTXOLogic {
	return &GetUTXOLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// UTXO 放在这里
func (l *GetUTXOLogic) GetUTXO(in *e4ting.ListReq) (*e4ting.ManyUtxoRes, error) {
	// fmt.Printf("%+v\n%+v\n", in, in.GetSearch())
	limit,offset,keyword := GetPage(in.GetSearch())
	items, count, err := l.svcCtx.UtxoModel.Search(l.ctx, limit, offset)
	if err != nil {
		return &e4ting.ManyUtxoRes{
			Code: 200,
			Err: err.Error(),
		}, nil
	}
	fmt.Printf("%d %d limit=%d,offset=%d,keyword=%s\n", count, len(items), limit,offset, keyword)
	return &e4ting.ManyUtxoRes{
		Code: 200,
		Total: count,
		Data: ToUtxoList(items),
	}, nil
}
